package com.itheima.web; /**
 * @author Xiao
 * @date 2021/9/4
 */

import com.itheima.utils.CheckCodeUtil;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet("/checkCodeServlet")
public class CheckCodeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //生成验证码
        ServletOutputStream sos = response.getOutputStream();
        String code = CheckCodeUtil.outputVerifyImage(100, 50, sos, 4);
        //存入session：当前会话有效
        HttpSession session = request.getSession();
        session.setAttribute("codeGen", code);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
